package com.jungle.bfi.controller;

import com.jungle.base.dao.SpecBuilder;
import com.jungle.base.domain.bo.BaseUserBo;
import com.jungle.base.domain.vo.JsonResult;
import com.jungle.bfi.domain.bo.DataCategoryBo;
import com.jungle.bfi.entity.DataCategoryPo;
import com.jungle.bfi.service.metadata.DataCategoryService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("dataCategory")
public class DataCategoryController {
    @Resource
    private DataCategoryService dataCategoryService;

    @PostMapping("store")
    public JsonResult<DataCategoryPo> save(@RequestBody DataCategoryBo qo) {
        DataCategoryPo dataCategoryPo = dataCategoryService.saveOrUpdate(qo, new BaseUserBo());
        return JsonResult.success(dataCategoryPo);
    }

    @GetMapping("delete")
    public JsonResult<Void> delete(@RequestParam String id) {
        dataCategoryService.deleteById(id);
        return JsonResult.success();
    }

    @PostMapping("list")
    public JsonResult<List<DataCategoryPo>> list(@RequestBody DataCategoryBo bo) {
        List<DataCategoryPo> list = dataCategoryService.findAll(new SpecBuilder<DataCategoryPo>(bo).toSpec());
        return JsonResult.success(list);
    }
}
